<template>
	<view>
		<view-head Title="血糖" :isShowR="true" @saveBack="saveBack"></view-head>
		<view class="view-content">
			<view class="list">
				<view class="item _df _jb _ac" hover-class="hover">
					<view class="title">
						血糖数值
					</view>
					<view class="info _df _ac">
						<u-input v-model.number="page.currentBloodSugar" placeholder="请输入" :clearable="false" type="text" :border="false" /> mmol/L <u-icon name="arrow-right" class="ml10" color="#aaa" size="28"></u-icon>
					</view>
					
				</view>
				<view class="item _df _jb _ac" @click="show=true" hover-class="hover">
					<view class="title">
						测量时间
					</view>
					<view class="info _df">
						{{page.createTime}} <u-icon class="ml10" name="arrow-right" color="#aaa" size="28"></u-icon>
					</view>
					
				</view>
				<!-- <view class="item _df _jb _ac" @click="showPop = true" hover-class="hover">
					<view class="title">
						设置时间段
					</view>
					<view class="info _df">
						{{times}}<u-icon class="ml10" name="arrow-right" color="#aaa" size="28"></u-icon>
					</view>
					
				</view> -->
			</view>
			
		</view>
		<u-select v-model="showPop" :list="timesList" @confirm="confirm"></u-select>
		<u-picker v-model="show" mode="time" :params="params" @confirm="confirm2"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value:'',
				time:'请选择',
				times:'请选择',
				show:false,
				showPop:false,
				mode:'date',
				timesList:[
					{
						value: '1',
						label: '早餐前'
					},
					{
						value: '1',
						label: '午餐前'
					},
					{
						value: '1',
						label: '晚餐前'
					},
					{
						value: '1',
						label: '睡觉前'
					}
				],
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				page:{
					currentBloodSugar:null,
					createTime:'请选择'
				}
			};
		},
		onLoad() {
			
		},
		onShow() {
			
		},
		methods:{
			addData(){
				let that = this
				uni.$_post({
					url: "addHealthData",
					that: that,
					params: that.page,
					success(res) {
						console.log(res)
						if(res.code == 0){
							that.$u.toast(res.msg)
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						}else{
							uni.showToast({
								title: '添加失败',
								duration: 2000,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: '添加失败',
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
			saveBack(){
				this.addData()
			},
			confirm(e) {
				console.log(e);
				this.times = e[0].label
			},
			confirm2(e) {
				console.log(e);
				this.page.createTime = e.year + '-' + e.month+ '-' + e.day +' '+ e.hour + ':' +e.minute
			},
		},
	}
</script>

<style lang="scss" scoped>
	/deep/.u-btn--primary{
		background-color: #FF4651;
		border-color: #FF4651;
	}
.view-content{
	padding: 0 30rpx 80rpx;
	.time-box{
		margin-bottom: 60rpx;
		.name{
			font-size: 34rpx;
			font-family: $uni-font-family-Bold;
			color: #000;
		}
		.time{
			font-size: 28rpx;
			font-family: $uni-font-family-Medium;
			color: #aaa;
		}
	}
	.subTitle{
		font-size: 24rpx;
		font-family: $uni-font-family-Medium;
		color: #888;
		margin-bottom: 24rpx;
	}
	.list{
		margin-bottom: 40rpx;
		.item{
			height: 80rpx;
			margin-bottom: 30rpx;
			padding: 0 20rpx;
			.title{
				font-size: 34rpx;
				font-family: $uni-font-family-Bold;
				color: #000;
			}
			.info{
				font-size: 28rpx;
				font-family: $uni-font-family-Medium;
				color: #aaa;
				margin-left: 10rpx;
			}
			/deep/.uni-input-input{
				font-size: 28rpx;
				font-family: $uni-font-family-Bold;
				color: #aaa;
				width: 100rpx;
				text-align: right;
				margin-right: 10rpx;
			}
		}
	}
}
</style>
